<?php
/**
 * Created by PhpStorm.
 * User: aijing
 * Date: 2018/4/12
 * Time: 21:19
 */
session_start();//启动会话
header("content-Type:text/html;charset=utf-8");?>
<html>
<head>
    <title>商品信息管理</title>
    <style type="text/css">
        html,body{
            padding:0;
            margin:0;
            background-color:#201612;
            height:100%;
            width:100%;
            color:#7e725e;
        }
    </style>
</head>
<body>
<center>
    <?php
    include("menu.php");//导入导航栏
    //1.导入配置文件
    require("dbconfig.php");
    //2.连接数据库，并选择数据库
    $link = @mysqli_connect("127.0.0.1","root","123456") or die("数据库连接失败");
    mysqli_select_db($link,"my_db");
    //3.获取要修改的商品信息
    $sql="select * from goods where id={$_GET['id']}";
    $result = mysqli_query($link,$sql);
    //4.判断是否获取到要编辑的商品信息
    if($result&&mysqli_num_rows($result)>0)
    {
        $shop=mysqli_fetch_assoc($result);//解析出要修改的商品信息
    }else
    {
        die("没有找到要修改的商品信息");
    }

    ?>
    <h3>编辑商品信息</h3>
    <form action="action.php?action=update" enctype="multipart/form-data" method="post">
        <input type="hidden" name="id" value="<?php echo $shop['id']; ?>" />

        <table border="0" width="300">
            <tr>
                <td align="right">名称：</td>
                <td><input type="text" name="name" value="<?php echo $shop['name']; ?>" /></td>
            </tr>
            <tr>
                <td align="right">类型：</td>
                <td>
                    <select name="typeid">
                        <?php
                        include("dbconfig.php");
                        foreach($typelist as $k=>$v)
                        {
                            $sd = ($shop['typeid']==$k)?"selected":"";//判断是否当前的类型
                            echo "<option value='{$k}' {$sd}>{$v}</option>";
                        }
                        ?>
                    </select>
                </td>
            </tr>
            <tr>
                <td align="right">单价：</td>
                <td><input type="text" name="price" value="<?php echo $shop['price']; ?>" /></td>
            </tr>
            <tr>
                <td align="right">库存：</td>
                <td><input type="text" name="total" value="<?php echo $shop['total']; ?>" /></td>
            </tr>
            <tr>
                <td align="right" valign="top">描述：</td>
                <td><textarea rows="5" cols="20" name="note"><?php echo $shop['note']; ?></textarea></td>
            </tr>

            <tr>
                <td colspan="2" align="center">
                    <input type="submit" value="修改" />&nbsp;&nbsp;
                    <input type="reset" value="重置" />
                </td>
            </tr>
            <tr>
                <td align="right" valign="top">&nbsp;</td>
            </tr>
        </table>
    </form>
</center>


</body>
</html>